package by.grsu.eo;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import by.grsu.eo.dao.CardDao;
import by.grsu.eo.dao.UserDao;
import by.grsu.eo.payment.system.Card;
import by.grsu.eo.payment.system.Role;
import by.grsu.eo.payment.system.Status;
import by.grsu.eo.payment.system.User;

import com.epam.grsulab.webapi.dao.base.Dao;
import com.epam.grsulab.webapi.entity.base.BaseEntity;
import com.epam.grsulab.webapi.tools.DataInitialiser;

@Component
public class DataInitializer implements DataInitialiser {

	private static final Logger logger = LoggerFactory.getLogger(DataInitializer.class);

	@Autowired
	private UserDao userDao;

	@Autowired
	private CardDao cardDao;

	@Override
	public void initData() {
		logger.info("Start data initialization");

		// create test User
		User user = new User();
		user.setFirstName("Alex");
		user.setLastName("Dart");
		user.setLogin("DART_ALEX");
		user.setPassword("1111");
		user.setRole(Role.cardUser);
		user = userDao.save(user);
		
		// create test Users Card
		final Card card = new Card();
		card.setBalance(200000);
		card.setHistory("add Money");
		card.setName("VISA");
		card.setIdNumber("dws12dahj653");
		card.setStatus(Status.active.toString());
		cardDao.save(card);
	}

	@Override
	public List<Dao<? extends BaseEntity>> getAllDAOs() {
		List<Dao<? extends BaseEntity>> list = new ArrayList<Dao<? extends BaseEntity>>();
		list.add(userDao);
		list.add(cardDao);
		return list;
	}
}
